<?php
/**
 * Created by PhpStorm.
 * User: lh
 * Date: 2020/1/20
 * Time: 11:55
 */

namespace App\Services\Sys;


use App\Models\Sys\Message;
use App\Models\Sys\User;

class SysService
{
    public static function add(string $path, $content, $user_id='', array $param=[]){

        if(!$user_id){
            $user_id = self::getUserIdByKey('name', '张译文');
        }
        Message::create([
            'path' => $path,
            'param' => json_encode($param),
            'content' => $content,
            'user_id' => $user_id,
        ]);
    }

    public static function getUserIdByKey($key, $value){
        $user = User::where($key, $value)->first();

        return $user ? $user->id : '';
    }
}